package com.binc.testspring.common.config;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    //一般消息队列
    @Bean
    public Queue queue(){
        return new Queue("queue1");//@RabbitListener(queues = "queue1")
    }

    //队列发送对象  （obj）
    @Bean
    public Queue objectQueue(){
        return new Queue("objectQueue1"); //@RabbitListener(queues = "objectQueue1")
    }

    //////////////////////////topic 配置
    //1、配置队列Queue
    @Bean
    public Queue queueMessage(){
        return new Queue("topic.a1"); //@RabbitListener(queues = "topic.a1") //只接受 主题 topic.a1的主题消息      尽量不要用单字母和数字
     }
    @Bean
    public Queue queueMessages_B(){
        return new Queue("topic.boss"); //@RabbitListener(queues = "topic.boss") //只接受 主题 topic.boss的主题消息    尽量不要用单字母和数字
    }
    @Bean
    public Queue queueMessages_d(){
        return new Queue("topic.d4"); //@RabbitListener(queues = "topicd4") //只接受 主题 topic.d4的主题消息    尽量不要用单字母和数字
    }
    @Bean
    public Queue queueMessagesAll(){
        return new Queue("topic.all"); //@RabbitListener(queues = "topicall") //只接受 主题 topic.all的主题消息    尽量不要用单字母和数字
    }
    //2、配置交换机Exchange
    @Bean("exchange1")
    public TopicExchange exchange(){
        return new TopicExchange("topicExchange1"); // 这个名字不要呦特殊符号
    }

    //3、将队列按照相应的规则绑定到交换机上
    @Bean
    Binding bindingExchangeMessage_a(){
        // 将发送到 交换机=topicExchange1、routingKey="topic.a1"消息发送给 监听 【topic.a1主题】的消费者 即：com.binc.testspring.rabbitmq.listener.RecieveTopic_a
        return BindingBuilder.bind(queueMessage()).to(exchange()).with("topic.a1");
    }
    @Bean
    Binding bindingExchangeMessages_b(){
        return BindingBuilder.bind(queueMessages_B()).to(exchange()).with("topic.boss");
    }
    @Bean
    Binding bindingExchangeMessages_d(){
        // 将发送到 交换机=topicExchange1、routingKey="topic.d4"消息发送给 监听 【topic.d4主题】的消费者 即：com.binc.testspring.rabbitmq.listener.RecieveTopic_d
        return BindingBuilder.bind(queueMessages_d()).to(exchange()).with("topic.d4");
    }
    @Bean
    Binding bindingExchangeMessages_all(){
        // 将发送到 交换机=topicExchange1、routingKey="topic.#"消息发送给 监听 【topic.all主题】的消费者 即：com.binc.testspring.rabbitmq.listener.RecieveTopic_All
        return BindingBuilder.bind(queueMessagesAll()).to(exchange()).with("topic.#");
    }
/////////////////////////////////////////////////上述 是一组topic配置






}
